home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Imaging / Show Previews < prev    next >
Encoding:
Text File  |  1999-03-04  |  1.7 KB  |  79 lines  |  [TEXT/ToyS]

  1. on open fsObjs
  2.     repeat with fsObj in fsObjs
  3.         set drawWin to ¬
  4.             display drawing titled ¬
  5.                 "Previewer" with dimensions {256, 288}
  6.         
  7.         ShowOne(drawWin, fsObj)
  8.         
  9.         display drawing drawWin with disposal
  10.     end repeat
  11. end open
  12.  
  13.  
  14. on ShowOne(drawWin, fsObj)
  15.     -- Get file name
  16.     set fname to catalog name of (basic info for fsObj)
  17.     
  18.     try
  19.         -- Get preview if available
  20.         set fsPreview to the resource fsObj ¬
  21.             of type "PICT" with index 1
  22.     on error
  23.         -- Else get icon
  24.         set fsPreview to (the icon for fsObj) as picture
  25.     end try
  26.     
  27.     -- Get the picture's box
  28.     set pictBox to picture bounds of ¬
  29.         (the picture info for fsPreview)
  30.     
  31.     -- Center it within 0,0,256,256
  32.     set myBox to PlaceInCenter(pictBox, {0, 0, 256, 256})
  33.     
  34.     -- Draw it double size (scale {2,2})
  35.     draw a picture into drawWin ¬
  36.         using data fsPreview ¬
  37.         inside of myBox ¬
  38.         with a clear slate
  39.     
  40.     -- Invert bottom
  41.     draw a box into drawWin ¬
  42.         inside of {0, 256, 256, 288} ¬
  43.         filling it with the pen
  44.     
  45.     -- Draw the name
  46.     draw a string into drawWin ¬
  47.         using data fname ¬
  48.         offset by {128, 280} ¬
  49.         using state {text size:18, text font:1, fg color:"FFFFFF"}
  50.     
  51.     pause for 2 with seconds timing
  52. end ShowOne
  53.  
  54.  
  55. on PlaceInCenter(src, dst)
  56.     set sW to (item 3 of src) - (item 1 of src)
  57.     set sH to (item 4 of src) - (item 2 of src)
  58.     set dW to (item 3 of dst) - (item 1 of dst)
  59.     set dH to (item 4 of dst) - (item 2 of dst)
  60.     
  61.     set r to dW / sW
  62.     set rH to dH / sH -- ratios
  63.     
  64.     if (rH < r) then set r to rH
  65.     
  66.     -- Round to a .25 ratio if > 1
  67.     if (r > 1) then ¬
  68.         set r to 0.25 * (round (r * 4))
  69.     
  70.     -- Scale the src
  71.     set sW to round (sW * r)
  72.     set sH to round (sH * r)
  73.     set mW to round ((dW - sW) / 2)
  74.     set mH to round ((dH - sH) / 2)
  75.     
  76.     -- Center it
  77.     return {mW, mH, mW + sW, mH + sH}
  78. end PlaceInCenter
  79.